//
//  BaseTableViewController.swift
//  01_新浪微博
//
//  Created by 黄蓉 on 15/12/13.
//  Copyright © 2015年 黄蓉. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {
//判断用户是登录
    var userLogin = UserAccount.loadAccount() != nil
    
    var visitorView: VisitorLoginView?
    
    func resigsterButtonClick() {
        print(__FUNCTION__)
    }
    
    func loginButtonClick() {
        
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
    }
    
    
    override func loadView() {
print("loadView")
     //如果没有登录或账号过期则显示 访客模式
        userLogin ? super.loadView() : setupVisitorView()

    }
    
    func setupVisitorView() {
        visitorView = VisitorLoginView()
        visitorView?.delegate = self
        
//        添加导航栏的按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "resigsterButtonClick")
        
        
        view = visitorView
    }


   }
